package cn.com.scooper.controller.data.xf;

import cn.com.scooper.common.resp.APIListJson;
import cn.com.scooper.common.resp.APIObjectJson;
import cn.com.scooper.common.resp.APIRespJson;
import cn.com.scooper.pojo.po.MineBasicDataPo;
import cn.com.scooper.service.xf.MineBasicDataService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.PostConstruct;
import java.util.List;

@RestController
@RequestMapping("/data/mineBasicData")
public class MineBasicDataController {
    @Autowired
    private MineBasicDataService mineBasicDataService;

    private static final Logger logger = LoggerFactory.getLogger(MineBasicDataController.class);

    /**
     * 获取单个MineBasicDataPo
     *
     * @param id
     * @return APIRespJson
     */
    @RequestMapping("/getMineBasicData")
    public APIRespJson getMineBasicData(@RequestParam int id) {
        MineBasicDataPo mineBasicDataPo = mineBasicDataService.getMineBasicData(id);
        return new APIObjectJson(mineBasicDataPo);
    }

    /**
     * 插入单个MineBasicDataPo
     *
     * @param mineBasicDataPo
     * @return APIRespJson
     */
    @RequestMapping("/saveMineBasicData")
    public APIRespJson saveMineBasicData(@ModelAttribute MineBasicDataPo mineBasicDataPo) {
        mineBasicDataService.saveMineBasicData(mineBasicDataPo);
        return new APIRespJson();
    }

    /**
     * 修改MineBasicDataPo
     *
     * @param mineBasicDataPo
     * @return APIRespJson
     */
    @RequestMapping("/updateMineBasicData")
    public APIRespJson updateMineBasicData(@ModelAttribute MineBasicDataPo mineBasicDataPo) {
        mineBasicDataService.updateMineBasicData(mineBasicDataPo);
        return new APIRespJson();
    }

    /**
     * 获取多个MineBasicDataPo
     *
     * @param mineBasicDataPo
     * @return APIRespJson
     */
    @RequestMapping("/listMineBasicData")
    public APIRespJson listMineBasicData(@ModelAttribute MineBasicDataPo mineBasicDataPo) {
        List<MineBasicDataPo> mineBasicDataPoList = mineBasicDataService.getMineBasicDataList(mineBasicDataPo);
        return new APIListJson<>(mineBasicDataPoList);
    }

    /**
     * 分页获取多个MineBasicDataPo
     *
     * @param mineBasicDataPo
     * @param pageNum
     * @param pageSize
     * @return APIRespJson
     */
    @RequestMapping("/pageMineBasicData")
    public APIRespJson pageMineBasicData(@ModelAttribute MineBasicDataPo mineBasicDataPo, @RequestParam(required = false, value = "pageNum", defaultValue = "1") int pageNum, @RequestParam(required = false, value = "pageSize", defaultValue = "10") int pageSize) {
        Page<MineBasicDataPo> mineBasicDataPoPage = mineBasicDataService.getMineBasicDataPage(mineBasicDataPo, pageNum, pageSize);
        PageInfo<MineBasicDataPo> pageInfo = new PageInfo<>(mineBasicDataPoPage);
        return new APIObjectJson(pageInfo);
    }

    /**
     * 手动触发上报矿山数据
     * @return
     */
    @RequestMapping("/reportMineBasicData")
    public APIRespJson reportMineBasicData(){
        mineBasicDataService.reportMineBasicData();
        return new APIRespJson();
    }

    /**
     * 手动触发删除矿山数据
     * @return
     */
    @GetMapping("/removeMineBasicData/{stMineId}")
    public APIRespJson reportMineBasicData(@PathVariable String stMineId){
        mineBasicDataService.removeMineBasicData(stMineId);
        return new APIRespJson();
    }
}